package com.zoe.onelink.governance.gateway.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.zoe.onelink.governance.gateway.model.NativeGatewayRoute;
import com.zoe.onelink.util.StrUtil;

import java.io.IOException;

/**
 * <p>标题: 路由格式序列化</p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2022</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2022-10-24
 */
public class GatewayRouteParamSerializer extends JsonSerializer<NativeGatewayRoute.GatewayRouteParam> {

    @Override
    public void serialize(NativeGatewayRoute.GatewayRouteParam value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        StringBuilder writeVal = new StringBuilder();
        writeVal.append(value.getName()).append("=");
        value.getArgs().values().forEach(val -> writeVal.append(val).append(StrUtil.COMMA));
        writeVal.deleteCharAt(writeVal.length() - 1);
        gen.writeString(writeVal.toString());
    }
}